package org.chen.spring.cloud.finchley.zuul.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.exception.ZuulException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.springframework.cloud.netflix.zuul.filters.support.FilterConstants.PRE_TYPE;

/**
 * @author chensj
 * @date 2020-02-09 07:12
 */
public class FirstPreFilter extends ZuulFilter {
  private static final Logger log = LoggerFactory.getLogger(FirstPreFilter.class);
  /**
   * 过滤器类型
   *
   * @return str
   */
  @Override
  public String filterType() {
    return PRE_TYPE;
  }

  /**
   * 定义当前过滤器的执行顺序
   *
   * @return int
   */
  @Override
  public int filterOrder() {
    return 0;
  }

  /**
   * 使用返回值来设定当前Filter是否执行
   *
   * @return boo
   */
  @Override
  public boolean shouldFilter() {
    return true;
  }

  /**
   * 核心逻辑，处理实际的业务逻辑
   *
   * @return
   * @throws ZuulException
   */
  @Override
  public Object run() throws ZuulException {
    log.info("这是一个自定义的ZuulFilter");
    return null;
  }
}
